import { onMounted, onUnmounted } from 'vue';

export function useAutoRefresh(fetchData, interval = 2000) {
  let refreshInterval = null;

  onMounted(() => {
    fetchData(); // 初次加载
    refreshInterval = setInterval(fetchData, interval);
  });

  onUnmounted(() => {
    if (refreshInterval) {
      clearInterval(refreshInterval);
    }
  });
}